package com.apexedu.eas.entity;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

/**
 * Created with IntelliJ IDEA.
 * User: chenjun
 * Date: 14-5-5
 * Time: 下午10:43
 * To change this template use File | Settings | File Templates.
 */
public class Dangan_con {
    String cmsuser;
    String cmspassword;
    String cmsurl;
    String cmsdriver;

    public Dangan_con()
    {
        this.cmsuser = "sa";
        this.cmspassword = "dangan@2014";

        this.cmsurl = "jdbc:sqlserver://10.100.100.121:1433;databasename=serverdb";
        this.cmsdriver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
    }

    public void insdangan(int paramInt, String paramString1, String paramString2, String paramString3, String paramString4, String paramString5, String paramString6, String paramString7, String paramString8, String paramString9, String paramString10)
    {
        String str = "insert into u_oatemp  (dir,ztm,wh,sj,bgq,gdfs,fj,gdr,sry,wz,yjr) values (?,?,?,?,?,?,?,?,?,?,?)";

        try {
            Class.forName(this.cmsdriver);
            Connection localConnection = DriverManager.getConnection(this.cmsurl, this.cmsuser, this.cmspassword);
            PreparedStatement localPreparedStatement = localConnection.prepareStatement(str);
            localPreparedStatement.setInt(1, paramInt);
            localPreparedStatement.setString(2, paramString1);
            localPreparedStatement.setString(3, paramString2);
            localPreparedStatement.setString(4, paramString3);
            localPreparedStatement.setString(5, paramString4);
            localPreparedStatement.setString(6, paramString5);
            localPreparedStatement.setString(7, paramString6);
            localPreparedStatement.setString(8, paramString7);
            localPreparedStatement.setString(9, paramString8);
            localPreparedStatement.setString(10, paramString9);
            localPreparedStatement.setString(11, paramString10);

            localPreparedStatement.executeUpdate();
            localPreparedStatement.close();
            localConnection.close();
        }
        catch (Exception localException) {
            localException.printStackTrace();
        }
    }

    /**
     *@bbdu 存储过程新增档案
     *
     **/
    public void insdawj(int dirname ,String dirjx,String ztm, String wh,String sj,String bgq,int gdfs,String fj,String gdr,String sry,String wz,String yjr)
    {


        try {
            Class.forName(this.cmsdriver);
            Connection localConnection = DriverManager.getConnection(this.cmsurl, this.cmsuser, this.cmspassword);

            CallableStatement cstmt = localConnection.prepareCall("{call dbo.insertda(?,?,?,?,?,?,?,?,?,?,?,?)}");
            cstmt.setInt(1, dirname);
            cstmt.setString(2, dirjx);
            cstmt.setString(3, ztm);
            cstmt.setString(4, wh);
            cstmt.setString(5, sj);
            cstmt.setString(6, bgq);
            cstmt.setInt(7, gdfs);
            cstmt.setString(8, fj);
            cstmt.setString(9, gdr);
            cstmt.setString(10, sry);
            cstmt.setString(11, wz);
            cstmt.setString(12, yjr);

            cstmt.execute();
            cstmt.close();
            localConnection.close();

        }
        catch (Exception localException) {
            localException.printStackTrace();
        }
    }



    public void IOCopy(String paramString1, String paramString2, int paramInt) {
        File localFile1 = new File(paramString1);
        File localFile2 = new File(paramString2);
        if (!localFile1.exists())
            System.out.println(localFile1.getName() + "文件不存在");
        else {
            System.out.println("存在");
        }
        byte[] arrayOfByte = new byte[(int)localFile1.length()];
        if (localFile1.isFile()) {
            try {
                FileInputStream localFileInputStream = new FileInputStream(localFile1);
                FileOutputStream localFileOutputStream = new FileOutputStream(localFile2);

                localFileInputStream.read(arrayOfByte);
                localFileOutputStream.write(arrayOfByte);
            }
            catch (Exception localException) {
                localException.printStackTrace();
            }
        } else if (localFile1.isDirectory()) {
            if (!localFile1.exists())
                localFile1.mkdir();
            String[] arrayOfString = localFile1.list();
            for (int i = 0; i < arrayOfString.length; i++) {
                String str = arrayOfString[i].split("\\.")[0];
                IOCopy(paramString1 + "/" + arrayOfString[i], paramString2 + "/oatemp_" + paramInt + "_4_" + str + ".doc", paramInt);
            }
        }
    }
}
